dynamic class com.c3d.mediaRotator.controllers.PanelController extends Object
{
    var _controllerType: String = "panel";
    var _subControllerIdentifier: String = "";
    var _parentPanelController = null;
    var _parentBaseController = null;
    var _panelAssetLoaded: Boolean = false;
    var _subPanelsPending: Number = 0;
    var _netLoadMarshall;
    var _panelLoaderTicketID;
    var _panelModel;
    var _panelSubviews;
    var _panelView;
    var _subPanelControllers;
    var internal_eventDispatcher;

    function PanelController($panelData, $parentPanelController, $viewWrapper)
    {
        super();
        this._subPanelsPending = 0;
        this.internal_eventDispatcher = new Object();
        mx.events.EventDispatcher.initialize(this.internal_eventDispatcher);
        this.internal_eventDispatcher.addEventListener("subviewReady", mx.utils.Delegate.create(this, this.onPanelViewReady));
        this.attachEventListeners();
        this._subControllerIdentifier = this.generateControllerIdentifier();
        this._subPanelControllers = new Array();
        this._netLoadMarshall = new com.c3d.common.net.NetLoadMarshall();
        this._panelSubviews = new Array();
        if ($parentPanelController.controllerType == "panel") 
        {
            this._parentPanelController = $parentPanelController;
            this._parentBaseController = $parentPanelController.baseController;
        }
        else 
        {
            this._parentPanelController = null;
            this._parentBaseController = $parentPanelController;
        }
        this._panelModel = new com.c3d.mediaRotator.data.PanelModel(this, $panelData);
        this._panelView = new com.c3d.mediaRotator.display.PanelView(this, $viewWrapper);
    }

    function generateControllerIdentifier()
    {
        var __reg2 = "";
        var __reg1 = Math.round(Math.random() * 1000000);
        return __reg1.toString();
    }

    function onPanelViewReady($event)
    {
        if (this._panelModel.__get__subviews().length > 0) 
        {
            com.c3d.common.events.CentralDispatch.dispatchEvent({type: "SUBVIEW_READY_PENDING", target: this});
            this.setupSubviews(this._panelModel.__get__subviews());
        }
        this.setupPanel();
    }

    function initialize()
    {
        this.renderPanel();
    }

    function activateView()
    {
        this._panelView.activate();
    }

    function deactivateView()
    {
        this._panelView.deactivate();
    }

    function setupPanel()
    {
        this._panelLoaderTicketID = this._netLoadMarshall.requestLoad(this._panelModel.__get__imageSrc(), "image", this._panelView.__get__assetWrapper());
        ++this._subPanelsPending;
    }

    function onPanelAssetLoadComplete($event)
    {
        if ($event.uid == this._panelLoaderTicketID && $event.uid != undefined) 
        {
            this._panelAssetLoaded = true;
            this.dispatchReadyStateToController();
        }
    }

    function dispatchReadyStateToController()
    {
        --this._subPanelsPending;
        if (this._subPanelsPending <= 0) 
        {
            if (this._parentPanelController == null) 
            {
                if (this._parentBaseController != null) 
                {
                    this._parentBaseController.childControllerReady(this);
                }
            }
            else 
            {
                this._parentPanelController.childControllerReady(this);
            }
            return;
        }
    }

    function childControllerReady($pc)
    {
        --this._subPanelsPending;
        if (this._subPanelsPending <= 0) 
        {
            this._parentBaseController.childControllerReady(this);
        }
    }

    function setupSubviews($sc)
    {
        this._panelSubviews = $sc;
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this._panelSubviews.length) 
            {
                return;
            }
            ++this._subPanelsPending;
            this._subPanelControllers.push(new com.c3d.mediaRotator.controllers.PanelController(this._panelSubviews[__reg2], this, this._panelView.__get__viewMovieClip()));
            ++__reg2;
        }
    }

    function renderPanel()
    {
        this._panelView.render(this._panelModel);
    }

    function forceRender()
    {
        this._panelView.render(this._panelModel);
    }

    function attachEventListeners()
    {
        com.c3d.common.events.CentralDispatch.addEventListener(com.c3d.common.events.NetworkEvent.NETWORK_REQUEST_COMPLETE, mx.utils.Delegate.create(this, this.onPanelAssetLoadComplete));
    }

    function onPanelTransitionBegin($event)
    {
        if (this._parentPanelController != null) 
        {
            return;
        }
    }

    function requestActivateButtons()
    {
    }

    function requestDeactivateButtons()
    {
    }

    function get controllerType()
    {
        return this._controllerType;
    }

    function get baseController()
    {
        return this._parentBaseController;
    }

    function get view()
    {
        return this._panelView;
    }

    function set view($pv)
    {
        this._panelView = $pv;
    }

    function get parentController()
    {
        return this._parentPanelController;
    }

    function set parentController($pc)
    {
        this._parentPanelController = $pc;
    }

    function get subControllerIdentifier()
    {
        return this._subControllerIdentifier;
    }

    function get navButtonInformation()
    {
        return new Object({label: this._panelModel.__get__label()});
    }

    function get maskInformation()
    {
        var __reg2 = new Object();
        var __reg3 = this._panelModel.__get__panelSize();
        if (__reg3 == null) 
        {
            __reg2 = __reg3;
        }
        else 
        {
            __reg2.height = __reg3.y;
            __reg2.width = __reg3.x;
            __reg2.cornerRadius = this._panelModel.panelCorners;
        }
        return __reg2;
    }

    function get locationInformation()
    {
        return this._panelModel.__get__panelLocation();
    }

    function get effectInformation()
    {
        return this._panelModel.__get__panelEffects();
    }

    function get linkInformation()
    {
        return this._panelModel.__get__linkInfo();
    }

    function get strokeInformation()
    {
        return this._panelModel.__get__strokeInfo();
    }

    function get panelTransitionDelay()
    {
        return this._panelModel.__get__transitionDelay();
    }

    function get panelModelData()
    {
        var __reg2 = new Object();
        __reg2 = this._panelModel.panelModelData;
        return __reg2;
    }

    function get panelAssetExtension()
    {
        return this._panelModel.__get__panelAssetExtension();
    }

}
